<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8"/>
    <title>个人资料</title>
    <meta name="keywords" content="">
    <meta name="description" content="">
    <meta name="renderer" content="webkit">
    <meta http-equiv="Cache-Control" content="no-siteapp"/>
    <meta name="mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <meta name="format-detection" content="telephone=no,email=no,address=no"/>
    <meta name="viewport" content="width=device-width,minimum-scale=1.0,maximum-scale=1.0,user-scalable=no">
    <link rel="stylesheet" href="../css/common.css"/>
    <link rel="stylesheet" href="../css/main.css"/>
    <style>
        .face img{
            width: 1rem;
            height: 1rem;
            border-radius: 50%;
        }
    </style>
</head>
<body>
<article>
    <form enctype="multipart/form-data" method="post" name="form" id="form">
        <label class="flex_sb plr24 ptb20 bw">
            <input type="file" name="files" hidden id="face"/>
            <span>头像</span>
            <div class="flex_a">
               <div class="face mr20"></div>
                <div class="arrow_right flex_a ml20">
                    <img src="../img/arrow_right.png"/>
                </div>
            </div>
        </label>
    </form>
    <div class="flex_sb bw plr24 h110 bdb mt20" onclick="$('.model_pane').show().children('.pane').fadeIn(300)">
        <span>昵称</span>
        <div class="arrow_right flex_a ml20">
            <span class="mr20 col9" id="nickname"></span>
            <img src="../img/arrow_right.png"/>
        </div>
    </div>
    <div class="flex_sb bw plr24 h110 bdb">
        <span>账号</span>
        <div class="arrow_right flex_a ml20">
            <span class="col9" id="phone">13632347040</span>
        </div>
    </div>
    <a href="./ad_set_password.html" class="flex_sb bw plr24 h110">
        <span>修改密码</span>
        <div class="arrow_right flex_a ml20">
            <img src="../img/arrow_right.png"/>
        </div>
    </a>
</article>
<section class="model_pane dpn model">
    <div class="pane dpn model">
        <p class="lh80 plr24">修改昵称</p>
        <div class="plr24 pb30">
            <label class="plr24 h90 flex_a border1">
                <input type="text" placeholder="请输入新的昵称" class="model_text nickname">
            </label>
        </div>
        <div class="flex lh90 tac">
            <div class="flex1 bgce" onclick="$('.model').hide();$('.model_text').val('')">取消</div>
            <div class="flex1 bgc1 colw" id="reset_name">确认</div>
        </div>
    </div>
</section>
</body>
</html>
<script src="../js/jquery-1.8.3.min.js"></script>
<script type="text/javascript" src="../js/dlc.js"></script>
<script src="../js/jquery.form.js"></script>
<script>
    $(function(){
        userInfo();
        function userInfo(){
            dlc_request('/api/apiAgent/queryAgentInfo',{'id':get_save('userId')}, function(res){
                console.log(res);
                if(res.code==1){
                    var res = res.data[0];
                    $('.face').html('<img src="'+(res.headImgUrl?res.headImgUrl:'../img/default.png')+'"/>');
                    if(res.name){
                        $('#nickname').text(res.name);
                    }
                    $('#phone').text(res.phone);
                }else{
                    dlctipbox.show(res.msg);
                }
            });
        }
        $('#reset_name').on('click',function(){
            var nickname = $('.nickname').val();
            if(isNull(nickname)){
                dlctipbox.show('请输入新的昵称');
            }else{
                dlc_request('',{'HTTP_API':'vv/usercenter/api/user/edit','nickname':nickname}, function(res){
                    console.log(res);
                    if(res.code==1){
                        $('.model').hide();
                        $('.model_text').val('');
                        userInfo();
                    }
                    dlctipbox.show(res.msg);
                });
            }
        });
        $('#face').on('change',function(){
            $('#form').ajaxSubmit({
                url:dlcUrl()+'/api/upload',
                type : 'POST',
                dataType:  'json',
                beforeSubmit:function(){
                    dlctipbox.loading('上传中..');
                },
                success: function(res){
                    console.log(res);
                    if(res.code==1){
                        dlc_request('/api/apiAgent/updataHeadImgOrInfo',{'id':get_save('userId'),'imgUrl':res.data.imgPath[0]}, function(res){
                            console.log(res);
                            if(res.code==1){
                                dlctipbox.clear();
                                userInfo();
                            }else{
                                dlctipbox.show(res.msg);
                            }
                        });
                    }else{
                        dlctipbox.show(res.msg);
                    }
                },
                error: function(err){
                    console.log(err);
                }
            });
        });
    });
</script>


















